#ifndef QNOTELISTITEMWIDGET_H
#define QNOTELISTITEMWIDGET_H

#include <MWidget>
#include "ui/MNoteListItemWidget.h"
//#include <QWebView>
#include "QvernoteAPI.h"
#include "QEnmlReader.h"
#include <QDebug>
//#include "QDeleteNotesView.h"
#include <MAbstractCellCreator>
#include "MeegoSupport.h"

class QNoteListItemWidget : public MAbstractCellCreator<MNoteListItemWidget>
{
    //Q_OBJECT

public:
    QNoteListItemWidget(bool isDeleteMode = false) : m_bDeleteMode(isDeleteMode) {
        setCellViewType("NoteListItem");
    }

    ~QNoteListItemWidget() { }

    void 	updateCell (const QModelIndex &index, MWidget *cell) const {
        QVariant checkData = index.data(Qt::CheckStateRole);
        Qt::CheckState checkState = (Qt::CheckState)checkData.value<int>();
        MNoteListItemWidget* m = (MNoteListItemWidget*)cell;
        QVariant data = index.data(Qt::DisplayRole);
        int noteptr = data.value<int>();
        Note* note = (Note*)(int*)noteptr;

        if(checkState == Qt::Checked)
            m->lDeleteMark->setPixmap(QPixmap(":/IconAdd/widgets_tickmark_list.png"));
        else
            m->lDeleteMark->setPixmap(QPixmap());

        if(!m_bDeleteMode)
        {
            if(note->resources.size() > 0)
                    m->lDeleteMark->setPixmap(QPixmap(":/IconAdd/email_attachment.png"));
        }

        /* draw note tags */
        vector<string>::iterator it;
        QString tagList = 0;
        for(it = note->tagNames.begin(); it < note->tagNames.end(); it++)
        {
                tagList += QString((*it).c_str()) + " ";
        }

        if(tagList.size() == 0)
                m->lNoteTags->setText(QApplication::trUtf8("No tags"));
        else
                m->lNoteTags->setText(tagList);

        QString noteTitle = QString::fromUtf8(note->title.c_str());

        //TODO m->lNoteTitle->setStyleSheet("color: black");
        m->lNoteTitle->setText(noteTitle);
        m->lNoteDate->setText(QDateTime::fromTime_t(note->created / 1000).toString("M/d/yy h:m AP"));
    }

    /*
    QSizeF 	cellSize () const {
        return QSizeF(MeegoSupport::desktopSize().width(), 70);
    }
    */

private:
    bool	m_bDeleteMode;
    bool	m_bItemMarked;
    bool	m_bMouseMoved;
};

#endif // QNOTELISTITEMWIDGET_H
